<?php



$this->uf_field[1] = "name";
	$this->uf_input[1]["ml"] = 50;
	$this->uf_input[1]["size"] = 15;
$this->uf_field[2] = "css_id";
	$this->uf_input[2]["type"] = "input_db";
	$this->uf_input[2]["abfrage"] = "SELECT id,name FROM ".$this->config["prefix"]."css";
	$this->uf_input[2]["id"] = "id";
	$this->uf_input[2]["name"] = "name";
$this->uf_field[3] = "tpl_dir";
	$this->uf_input[3]["ml"] = 50;
	$this->uf_input[3]["size"] = 15;
$this->uf_field[4] = "cs";
	$this->uf_input[4]["ml"] = 2;
	$this->uf_input[4]["size"] = 2;
$this->uf_field[5] = "cp";
	$this->uf_input[5]["ml"] = 2;
	$this->uf_input[5]["size"] = 2;
	
$style = $this->fun_sg2var("style");
$style = $this->uf_form_conf_def($style,array("show","new","edit","do_edit","del"),"show");

$this->module_new_value["action"] = "style";

if ($style == "show") {
	$erg = $this->db_abfrage_q("SELECT ".$this->config["prefix"]."style.id AS style_id,".$this->config["prefix"]."style.name AS style_name,".$this->config["prefix"]."style.tpl_dir AS tpl_dir,".$this->config["prefix"]."css.name AS css_name FROM ".$this->config["prefix"]."style LEFT JOIN ".$this->config["prefix"]."css ON (".$this->config["prefix"]."style.css_id = ".$this->config["prefix"]."css.id)");
	$style_ones = "";
	while($db_style = $this->db_abfrage_fetch($erg)){
		$edit_link = $this->fun_make_link("admin.php","style=edit&style_id=".$db_style["style_id"]."");
		$this->tpl_load("style_show_one","admin/");
		$this->tpl_replace_vars(array("style_name" => $db_style["style_name"], "css_name" => $db_style["css_name"], "tpl_dir" => $db_style["tpl_dir"], "edit_link" => $edit_link,"style_id" => $db_style["style_id"]));
		$style_ones .= $this->tpl_output();
	} // while
	$hidden_array["style"] = "del";
	$hidden_form = $this->uf_create_hidden_form($hidden_array);
	unset($hidden_array);
	$hidden_array["style"] = "new";
	$var_array["tpl_dir"] = "standard/";
	$var_array["cs"] = 1;
	$var_array["cp"] = 1;
	$style_new_form = $this->uf_create_complete_form("admin_style_new_title",$hidden_array,"admin_style_new_submit","form_reset","complete_form","uf/","admin.php",$var_array,"admin_style_one_");
	$this->tpl_load("style_show","admin/");
	$this->module_new_value["action"] = "css";
	$css_link = $this->fun_make_link("admin.php");
	$this->tpl_replace_vars(array("hidden_form" => $hidden_form, "css_link" => $css_link,"style_ones" => $style_ones,"style_new_form" => $style_new_form));
	$nc_main = $this->tpl_output();   
}elseif ($style == "edit") {
	$valid_style = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."style WHERE id=\"".$_GET["style_id"]."\"");
	if ($valid_style == 1) {
	    $db_style = $this->db_abfrage_az("SELECT * FROM ".$this->config["prefix"]."style WHERE id=\"".$_GET["style_id"]."\"");
		//$edit_form = $uf->input_creator($field_array,$st,$input_type,"admin_style_one_","text","icreator_one","admin/");
		$hidden_array["style"] = "do_edit";
		$hidden_array["style_id"] = $_GET["style_id"];
		$nc_main = $this->uf_create_complete_form("admin_style_edit_title",$hidden_array,"admin_style_edit_submit","form_reset","complete_form","uf/","admin.php",$db_style,"admin_style_one_");
	}else {
		$this->w_leitung["number"] = 7;
		$this->w_leitung["url"] = $this->fun_make_link("admin.php","action=style");
		$this->message_red[] = 10;
	}
}elseif ($style == "do_edit") {
	$valid_style = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."style WHERE id=\"".$_POST["style_id"]."\"");
	if ($valid_style == 1) {
	    list($input_array,$abfrage) = $this->uf_create_array_conf("update");
		$valid_input = $this->uf_form_conf($input_array);
		if ($valid_input == 1) {
		    $this->db_abfrage_q("UPDATE ".$this->config["prefix"]."style SET $abfrage WHERE id=\"".$_POST["style_id"]."\"");
			$this->message_green[] = 15;
			$this->w_leitung["number"] = 7;
			$this->w_leitung["url"] = $this->fun_make_link("admin.php");
		}else {
			$this->w_leitung["number"] = 1;
			$this->message_red[] = 1;
		}
	}else {
		$this->w_leitung["number"] = 7;
		$this->message_red[] = 10;
	}
}
elseif ($style == "new") {
	list($return,$abfrage,$abfrage2) = $this->uf_create_array_conf("insert");
	$anzahl_styles_name = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."style WHERE name=\"".$_POST["name"]."\"");
	if($anzahl_styles_name == 0) {
		$valid_input = $this->uf_form_conf($return);
		if ($valid_input == 1) {
		    $valid_css = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."css WHERE id = \"".$_POST["css_id"]."\"");
			if ($valid_css == 1) {
				$this->db_abfrage_q("INSERT ".$this->config["prefix"]."style ($abfrage) VALUES ($abfrage2)");
				$this->message_green[] = 13;
				$this->w_leitung["url"] = $this->fun_make_link("admin.php","action=style");
				$this->w_leitung["number"] = 1;
			}else {
				$this->message_red[] = 7;
				$this->w_leitung["number"] = 1;
			}
		}else {
			$this->message_red[] = 1;
			$this->w_leitung["number"] = 1;
		}
	}else {
		$this->message_red[] = 19;	
		$this->w_leitung["number"] = 1;
	}
}elseif ($style == "del") {
	if (isset($_POST["del_style"])) {
		$st_ids = array();
		$this->anzahl = 0;
		$this->anzahl_del = 0;
	    foreach ($_POST["del_style"] as $style_id) {
			$anzahl_styles = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."style");
			if ($anzahl_styles > 1 AND $style_id != $this->db_config["default_style"]) {
			    array_push($st_ids,$style_id);
				$this->anzahl_del++;
			}
			$this->anzahl++;
		}
		if($this->anzahl_del >= 1) {
			$abfrage = $this->uf_create_where_part($st_ids);
			$this->db_abfrage_q("DELETE FROM ".$this->config["prefix"]."style WHERE $abfrage");
			$this->message_green[] = 14;
		}else $this->message_red[] = 9;
	}else $this->message_red[] = 8;
	$this->w_leitung["number"] = 7;
	$this->w_leitung["url"] = $this->fun_make_link("admin.php","action=style");
}


?>